

set more off
mat drop _all


use "$path_data/data/learning_curve.dta", clear



label define level_name2 0 "6A" 200 "5A" 400 "4A" 600 "3A" 800 "2A" 1000 "A" 1200 "B" ///
1400 "C" 1600 "D" 2000 "E" 2200 "F" 2400 "G"

  



gen initial_cog_noncog = .
replace initial_cog_noncog = 1 if above_rosen == 1 & above_ptcog == 1
replace initial_cog_noncog = 2 if above_rosen == 0 & above_ptcog == 1
replace initial_cog_noncog = 3 if above_rosen == 1 & above_ptcog == 0
replace initial_cog_noncog = 4 if above_rosen == 0 & above_ptcog == 0


tab continuous_day



sort student_no year month day
by student_no: gen n_kumon_days = _n if score_10 != . | score_1!= . | ///
score_2 != . | score_3!= . | score_4 != . | score_5!= . | ///
score_6 != . | score_7!= . | score_8 != . | score_9!= . 




preserve
xtset, clear
collapse (mean) mean_lv = level_sheet_convert (sd) sd = level_sheet_convert, by(initial_cog_noncog n_kumon_days) fast
xtset initial_cog_noncog n_kumon_days

label values mean_lv level_name2


*gen mean_lv_plus = mean_lv + sd
*gen mean_lv_minus = mean_lv - sd
sort n_kumon_days

twoway (line mean_lv n_kumon_days if initial_cog_noncog == 1 & n_kumon_days < 150, lcolor(black)) ///
(line mean_lv n_kumon_days if initial_cog_noncog == 2 & n_kumon_days < 150, lcolor(blue) lpattern(dash)) ///
(line mean_lv n_kumon_days if initial_cog_noncog == 3 & n_kumon_days < 150, lcolor(red) lpattern(dot)) ///
(line mean_lv n_kumon_days if initial_cog_noncog == 4 & n_kumon_days < 150, lcolor(green) lpattern(longdash)), ///
graphregion(color(white)) plotregion(fcolor(white)) graphregion(margin(medlarge)) ///
ylabel(400(200)2000, angle(0) grid) xlabel(0(50)150 ,val) xtitle("Cumulative Days of Kumon Sessions") ytitle("Level of Worksheet") ///
legend(order(1 "a") pos(5) ring(1) ///
col(1) si(small) rowgap(0.2)) title("Learning Curve: Average") ///
legend(order(1 "Students with Initially High Cognitive and High Non-cognitive Ability" ///
 2 "Students with Initially High Cognitive and Low Non-cognitive Ability" ///
 3 "Students with Initially Low Cognitive and High Non-cognitive Ability" ///
 4 "Students with Initially Low Cognitive and Low Non-cognitive Ability"))
graph export "$pardir/figureF1.pdf", replace as(pdf)


restore 

